package geguol.cc.widgetapplication.activity;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.AutoCompleteTextView;
import android.widget.SearchView;

import java.util.ArrayList;
import java.util.List;

import geguol.cc.widgetapplication.R;
import geguol.cc.widgetapplication.adapter.AutoCompleteBaseAdapter;
import geguol.cc.widgetapplication.bean.TestBean;

public class SearchActivity2 extends AppCompatActivity {

	private SearchView searchView;
	private AutoCompleteTextView autoCompleteTextView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_search2);
		searchView = (SearchView) findViewById(R.id.search_view);
		autoCompleteTextView = (AutoCompleteTextView) searchView.findViewById(R.id.search_src_text);
		final SearchAdapter mAdapter = new SearchAdapter(this);
		autoCompleteTextView.setAdapter(mAdapter);
		searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
			@Override
			public boolean onQueryTextSubmit(String query) {
				searchView.setQuery(query,true);
				return false;
			}

			@Override
			public boolean onQueryTextChange(String newText) {
				return false;
			}
		});

	}

	private class SearchAdapter extends AutoCompleteBaseAdapter<TestBean>{

		public SearchAdapter(Context context) {
			super(context);
		}

		@Override
		public List<TestBean> getNewDataSources(CharSequence prefix) {
			List<TestBean> testBeens = new ArrayList<>();
			for (int i = 0; i < 4; i++) {
				TestBean testBean = new TestBean(i,i+"我是测试数据哦");
				testBeens.add(testBean);
			}
			return testBeens;
		}
	}
}
